<?php

declare(strict_types=1);

namespace App\Request;

use Hyperf\Validation\Request\FormRequest;
use Hyperf\Validation\Rule;

class DcenterUserRequest extends FormRequest
{
    protected array $scenes = [
        'add' => ['username', 'password', 'role_id', 'status'],
        'edit' => ['uid', 'username', 'role_id', 'status'],
    ];
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'uid' => 'required|integer',
            'username' => 'required|min:2|max:50',
            'password' => 'regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{6,}$/',
            'role_id' => 'required',
            'status' => 'required|integer',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息
     */
    public function messages(): array
    {
        return [
            'uid.required' => '参数错误-0',
            'uid.integer' => '参数错误-1',
            'username.required' => '账号不能为空',
            'username.min' => '账号格式不正确',
            'username.max' => '账号格式不正确',
            'password.regex' => '密码格式不正确',
            'role_id.required' => '角色不能为空',
            'status.required' => '格式错误-2',
            'status.integer' => '格式错误-3',
        ];
    }
}
